本文共 11022 字,大约阅读时间需要 36 分钟。
1.shell 脚本:linux centos 7 系统
2.Python shell 脚本:window 系统 3.其他:python selenium 模块,谷歌浏览器, 谷歌浏览器驱动。4.discuz 链接: 提取码:mijf
vim lnmp.sh
#!/bin/bash
#this is auto install lamp or lnmp shell!#apache安装
apache(){ #apache编译安装cd /opt/httpd-2.4.29 &&./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi &&make && make install &&cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd##修改配置文件#在/etc/init.d/httpd文件中第二行插入2段sed -i "2i#chkconfig: 35 85 21 \n\#description: Apache is a World Wide Web server." /etc/init.d/httpd#将Listen 80 替换成 Listen $ip:80 ,$ip为变量,是本机ip地址(特别注意变量的替换方法)sed -i "s/^Listen 80/Listen $ip:80/g" /usr/local/httpd/conf/httpd.conf##优化服务ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd ;ln -s /usr/local/httpd/bin/* /usr/local/bin/chkconfig --add httpdsystemctl daemon-reloadsystemctl start httpd##检查端口和网页测试port=`netstat -anpt | grep httpd | wc -l`if [ $? -eq 0 ] && [ $port -ne 0 ]; thenecho -e "\033\t\t\t[44;32m test \033[0m"read -p "input result:(y/n) " uif [ $u == "y" ]; thenecho -e "\033\t\t\t[32m apache install success!\033[0m"elseecho -e "\033\t\t\t[5;31m apache install fail!\033[0m"fielse#"-e" 为转义,\033为固定格式(同 \e),"/t"为制表位,同tab键,"5"为闪烁,31m为字体颜色,此处红色,"\033[0m "为固定结束格式echo -e "\033\t\t\t[5;31m apache install fail,check!!\033[0m"exit 0fi}##安装nginxnginxt(){ #编译安装useradd -M -s /sbin/nologin nginxcd /opt/nginx-1.12.0/./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_stub_status_modulemake && make installln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ ;nginx &&nginx -t;#检查服务启动stat=`netstat -ntap | grep "80" | wc -l`if [ $? -eq 0 ]&&[ $stat -ne 0 ] ;thenecho -e "\033\t\t\t[32m nginx install success!!\033[0m" elseecho -e "\033\t\t\t[5;31m nginx install fail!!\033[0m"exit 0fi}##mysql安装mysql_con(){ #编译安装#判断有无/usr/local/mysql目录,没有就创建[ ! -d /usr/local/mysql ] && mkdir -p /usr/local/mysql/usr/sbin/useradd -s /sbin/nologin mysqlcd /opt/mysql-5.5.24cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS=all \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DENABLED_LOCAL_INFILE=1 \-DMYSQL_DATADIR=/home/mysql \-DMYSQL_USER=mysql \-DMYSQL_TCP_PORT=3306if [ $? -eq 0 ];thenmake && make install##修改配置文件echo "export PATH=$PATH:/usr/local/mysql/bin/ " >> /etc/profilesource /etc/profile && chown -R mysql:mysql /usr/local/mysql &&cd /usr/local/mysql/support-files &&cp my-medium.cnf /etc/my.cnf &&cp mysql.server /etc/init.d/mysqld &&chmod 755 /etc/init.d/mysqld &&chkconfig --add /etc/init.d/mysqld ;chkconfig mysqld --level 35 onelseecho -e "\e\t\t\t[5;31m set error,check ![0m"exit 1fi#初始化数据库/usr/local/mysql/scripts/mysql_install_db \--user=mysql \--ldata=/var/lib/mysql \--basedir=/usr/local/mysql \--datadir=/home/mysqlln -s /usr/local/mysql/bin/ /usr/local/bin/##搜索basedir=,datadir=,并替换sed -i 's#^basedir=.$#basedir=/usr/local/mysql#' /etc/init.d/mysqldsed -i 's#^datadir=.*$#datadir=/home/mysql#' /etc/init.d/mysqld#mysql启动和检查systemctl daemon-reload && systemctl start mysqldport=`netstat -ntap | grep mysql |wc -l`if [ $? -eq 0 ]&&[ $port -ne 0 ];thenecho -e "\033\t\t\t[32m mysql install success!! \033[0m"elseecho -e "\033\t\t\t[5;31m mysql install fail,check!! \033[0m"exit 0fi}##apache-php安装apa_php(){ #php编译安装cd /opt/php-5.6.11./configure \--prefix=/usr/local/php5 \--with-gd \--with-zlib \--with-apxs2=/usr/local/httpd/bin/apxs \--with-mysql=/usr/local/mysql \--with-config-file-path=/usr/local/php5 \--enable-mbstringmake && make install &&cp php.ini-development /usr/local/php5/php.ini && ln -s /usr/local/php5/bin/ /usr/local/bin/ ; ln -s /usr/local/php5/sbin/ /usr/local/sbin/ ;useradd -M -s /sbin/nologin php#检查httpd.conf文件中是否有php5_module,并统计
num=`cat /usr/local/httpd/conf/httpd.conf | grep "php5_module" | wc -l`#判断是否有php5_moduleif [ $num -eq 0 ] ;thenecho -e "\e\t\t\t[5;31m no php5_module, check! \e[0m"exit 0elseecho -e "\e\t\t\t[32m php5_module is exist! \e[0m"fi##修改httpd配置,测试php#在第258行行尾加index.phpsed -i '258s/$/ index.php/' /usr/local/httpd/conf/httpd.conf#在383行插入相关文件sed -i "383iAddType application/x-httpd-php .php\n\AddType application/x-httpd-php-source .phps" /usr/local/httpd/conf/httpd.confsystemctl restart httpd##echo文件到index.php里面echo -e "<?php\nphpinfo();\n?>" >>/usr/local/httpd/htdocs/index.php#输出用户测试网页链接echo -e "\e\t\t\t[5;34m test \e[0m"#php连接mysql测试read -p "if connect mysql? (y/n)? " anif [ $an == "y" ];then#echo文件到index.php中,注意单引号中不识别$ipecho -e '<?php\n$link=mysql_connect(localhost);\nif($link) echo "Success!!";\nelse echo "Fail!!";\nmysql_close();\n?>' >>/usr/local/httpd/htdocs/index1.php#将localhost替换成 $ip','root' ,注意双引号中不识别$link(要特别注意单引号和双引号之间的区别!)sed -i "s/localhost/'$ip','root'/g" /usr/local/httpd/htdocs/index1.phpecho -e "\e\t\t\t[32m \e[0m"elseecho -e "\e\t\t\t[32m lamp install finish!\e[0m"exit 0fi}##nginx-php安装nginx_php(){ useradd -M -s /sbin/nologin phpcd /opt/php-5.6.11./configure \--prefix=/usr/local/php5 \--with-gd \--with-zlib \--with-mysql=/usr/local/mysql \--with-config-file-path=/usr/local/php5 \--enable-mbstring \--with-jpeg-dir \--with-openssl \--disable-ipv6 \--enable-fpmmake && make install#安装gd和修改php配置文件cd /opt/zend-loader-php5.5-linux-x86_64/ && cp ZendGuardLoader.so /usr/local/php5/lib/php#echo -e "[Zend Guard Loader]\nzend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >>/usr/local/php5/php.inicd /usr/local/php5/etc/ && cp php-fpm.conf.default php-fpm.conf#替换文件sed -i 's#^user = .$#user = php#' php-fpm.confsed -i 's#^group = .$#group = php#' php-fpm.confsed -i 's#^pm.max_children = .$#pm.max_children = 50#' php-fpm.confsed -i 's#^pm.max_spare_server = .$#pm.max_children = 35#' php-fpm.confsed -i 's#^pm.min_spare_server = .$#pm.min_children = 5#' php-fpm.confsed -i 's#^pm.start_server = .$#pm.min_children = 20#' php-fpm.conf#php服务启动和检查/usr/local/php5/sbin/php-fpmport=`netstat -ntap | grep ":9000" | wc -l`if [ $? -eq 0 ]&&[ $port -ne 0 ];thenecho -e "\033\t\t\t[32m php install success! \033[0m"elseecho -e "\033\t\t\t[5;31m php install fail! \033[0m"exit 0fi}##nginx和php结合ngin_vim(){ #修改nginx配置mkdir -p /var/www/html/btcom#将45行 ; 替换成index.php; (或者在 ; 前面加 index.php,这个命令不好写)sed -i '45s/;/ index.php;/g' /usr/local/nginx/conf/nginx.conf#在64行插入sed -i "64ilocation ~ .php$ {\n\root /var/www/html/btcom;\n\fastcgi_pass 127.0.0.1:9000;\n\fastcgi_index index.php;\n\fastcgi_param SCRIPT_FILENAME;\n\include fastcgi_params;\n\}" /usr/local/nginx/conf/nginx.conf#在68行;后插入语句,注意双引号不识别$document_root$fastcgi_script_name,才用单引号重新插入sed -i '68s/;/ $document_root$fastcgi_script_name;/g' /usr/local/nginx/conf/nginx.confecho -e "<?php\nphpinfo();\n?>" >>/var/www/html/btcom/index.phpnginx -s reloadecho -e "\e[32m test \e[0m"##php连接mysqlread -p "php connect mysql (y/n)? " answerif [ $answer == "y" ];then#echo文件,注意但,双引号,原因同上echo -e '<?php\n$link=mysql_connect(localhost);\nif($link) echo "Success!!";\nelse echo "Fail!!";\nmysql_close();\n?>' >>/var/www/html/btcom/index1.phpsed -i "s/localhost/'$ip','root'/g" /var/www/html/btcom/index1.phpecho -e "\e\t\t\t[32m test \e[0m"elseecho -e "\e\t\t\t[32m lnmp install finish!\e[0m"exit 0fi}##论坛安装discuz(){ #不登录mysql,创建数据库,授权。mysql -e "create database bbs;grant all on bbs.* To 'bbsuser'@'%' identified BY 'admin123';flush privileges;"#bbsuser 连接 数据库echo -e '<?php\n$link=mysql_connect(localhost);\nif($link) echo "Success!!";\nelse echo "Fail!!";\nmysql_close();\n?>' >>/usr/local/httpd/htdocs/index1.phpsed -i "s/localhost/'$ip','bbsuser','admin123'/g" /usr/local/httpd/htdocs/index1.php#去网页验证连接数据库是否成功echo -e "\e\t\t\t[32m test \e[0m"#进行人机交互,连接成功进行discuz安装read -p "bbs connect mysql success (y/n)? " awif [ $aw == "y" ];thenunzip Discuz_X2.5_SC_UTF8.zip -d /opt && mkdir -p /usr/local/httpd/htdocs/bbs/ &&cp -r /opt/upload/ /usr/local/httpd/htdocs/bbs/ &&cd /opt/httpd/htdocs/bbs/upload/chown -R daemon ./config/ chown -R daemon ./data/chown -R daemon ./uc_client/chown -R daemon ./uc_server/data/sed -i '927s/;date.timezone =/ date.timezone = UTC/g' /usr/local/php5/php.ini#输出完成信息,提醒用户去网页安装,给出安装链接echo -e "\e\t\t\t[5;31m you can install discuz at \e[0m"#数据库连接失败,直接退出脚本else echo -e "\e\t\t\t[5;31m bbs connect mysql fail,check! \e[0m"exit 0fi}##执行package.sh脚本./package.sh#关闭防火墙,增强性systemctl stop firewalld.servicesetenforce 0#过滤出本机ipip=`ifconfig ens33 | grep "netmask" | awk '{print $2}'`#查看e.sh,将2个脚本连接起来num=`cat /root/e.sh`#2脚本已经建立连接,删除e.sh,防止占用空间rm -rf e.sh#lamp脚本安装if [ $num == "lamp" ]then#apache 安装apache#mysql 安装mysql_con#apache和php连接apa_phpdiscuz#lnmp脚本安装elif [ $num == "lnmp" ]then#nginx.mysql,php安装nginxt &&mysql_con &&nginx_php#修改nginx配置文件ngin_vimdiscuzelseecho -e "\e\t\t\t[5;31m input error,check! \e[0m"exit 1fi
chmod +x *.sh
./lnmp.sh
from selenium import webdriver
import time#采用谷歌浏览器driver = webdriver.Chrome()#进入安装链接driver.get("")print(driver.title)#定位“同意”元素,点击鼠标driver.find_element_by_name("submit").click()
#定位“下一步”元素,点击鼠标
driver.find_element_by_xpath("//input[@type='submit']").click()
#定位“下一步”元素,点击鼠标
driver.find_element_by_name("submitname").click()
#定位"数据库服务器填写框", 清除原有文本
driver.find_element_by_name("dbinfo[dbhost]").clear()#在上一步,清除文本后,输入新文本driver.find_element_by_name("dbinfo[dbhost]").send_keys("192.168.65.185")#定位,清除文本driver.find_element_by_name("dbinfo[dbname]").clear()#填写新文本driver.find_element_by_name("dbinfo[dbname]").send_keys("bbs")driver.find_element_by_name("dbinfo[dbuser]").clear()driver.find_element_by_name("dbinfo[dbuser]").send_keys("bbsuser")driver.find_element_by_name("dbinfo[dbpw]").clear()driver.find_element_by_name("dbinfo[dbpw]").send_keys("admin123")driver.find_element_by_name("admininfo[password]").send_keys("admin123")driver.find_element_by_name("admininfo[password2]").send_keys("admin123")#定位"下一步"元素,点击鼠标driver.find_element_by_name("submitname").click()
#跳转到论坛首页
driver.get("")
print(driver.title)#自动输入用户名,密码
driver.find_element_by_name("username").send_keys("admin")driver.find_element_by_name("password").send_keys("admin123")#点击自动登录
driver.find_element_by_xpath("//button[@type='submit']").click()#点击登录
driver.find_element_by_name("cookietime").click()
1.本次脚本是在上一篇博客的基础上完成的,package.sh脚本查看上一篇博客https://blog.51cto.com/13760351/2352154
2.window 网页自动安装方法是采用python selenium 模块,这部分知识将在后面的博客中发布,请期待!3.此脚本不适用于新手安装discuz论坛(脚本执行太快,出现问题,无法找到问题,解决问题),只适合作为shell和Python shell 脚本爱好者练习使用。4.脚本安装的方法很多,这只是其中一种,若大家有更方便快捷的脚本,欢迎留言交流!5.脚本资料下载地址:6.每个人的服务器地址不一样,需要手动去python shell修改,shell脚本执行完成后,需要手动去执行python shell 脚本!
转载于:https://blog.51cto.com/13760351/2364304