一、组成
lamp搭建。
二、前端(网页服务)
2.1 Apache搭建(编译安装httpd服务)
#!/bin/bash #####httpd##### #前提条件,opt目录下有对应的压缩文件 cd /opt #将所有需要的压缩文件通过xshell导入,或者从官网下载 systemctl disable --now firewalld setenforce 0 #关闭防火墙与selinux功能 yum install -y gcc gcc-c++ make pcre pcre-devel expat-devel perl #安装编译所需环境 tar xf apr-1.6.2.tar.gz tar xf apr-util-1.6.0.tar.gz tar xf httpd-2.4.29.tar.bz2 #解压软件包 mv apr-1.6.2 httpd-2.4.29/srclib/apr mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util #将解压文件放到对应位置并重命名 cd httpd-2.4.29/ ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi #配置脚本功能 make -j 4 && make install #四核编译并安装服务软件 mv /usr/local/httpd/conf/httpd.conf /opt/ mv /opt/httpd.conf /usr/local/httpd/conf/ ln -s /usr/local/httpd/conf/httpd.conf /etc/ ln -s /usr/local/httpd/bin/* /usr/local/bin #创建配置/命令的软链接,方便后期修改配置与使用命令 cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #将命令加入到开机服务进程中 chmod +x /etc/init.d/httpd #赋予脚本执行权限 sed -i.bak '1i #!/bin/bash\ #chkconfig: 235 80 20\ #description:apache service' /etc/init.d/httpd #备份并修改httpd服务启动配置文件 chkconfig --add httpd #将httpd服务添加到系统启动项中 systemctl start httpd #启动httpd服务 IP=`ifconfig |grep netmask -m 1 |awk '{print $2}'` sed -i.bak -e "52 s/Listen.*/Listen ${IP}/" -e "197 s/.*ServerName.*/ServerName www.kgc.com:80/" /etc/httpd.conf #备份并修改httpd主配置文件 echo "${IP} www.kgc.com" >>/etc/hosts #将指定域名添加到本地域名解析中 touch /etc/hosts
三、后台
3.1 sql配置(数据库搭建)
#!/bin/bash cd /opt yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake tar zxvf mysql-5.7.17.tar.gz tar zxvf boost_1_59_0.tar.gz mv boost_1_59_0 /usr/local/boost cd /opt/mysql-5.7.17/ cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DSYSCONFDIR=/etc \ -DSYSTEMD_PID_DIR=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=/usr/local/boost \ -DWITH_SYSTEMD=1 make -j 4 && make install useradd -M -s /sbin/nologin mysql echo "[client] port = 3306 socket = /usr/local/mysql/mysql.sock [mysql] port = 3306 socket = /usr/local/mysql/mysql.sock auto-rehash [mysqld] user = mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data port = 3306 character-set-server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket=/usr/local/mysql/mysql.sock bind-address = 0.0.0.0 skip-name-resolve max_connections=2048 default-storage-engine=INNODB max_allowed_packet=16M server-id = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES" > /etc/my.cnf chown -R mysql:mysql /usr/local/mysql/ chown mysql:mysql /etc/my.cnf echo "export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH" >> /etc/profile source /etc/profile cd /usr/local/mysql/bin/ ./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload systemctl enable --now mysqld netstat -anpt | grep 3306 yum install -y expect /usr/bin/expect <<EOF spawn mysqladmin -u root -p password "abc123" expect "Enter password" {send "\r"} expect eof EOF /usr/bin/expect <<EOF spawn mysql -u root -p expect "Enter password" {send "abc123\r"} expect "mysql" {send "grant all privileges on *.* to 'root'@'%' identified by 'abc123';\r"} expect "mysql" {send "quit\r"} expect eof EOF
四、桥梁
4.1 PHP配置
#!/bin/bash yum -y install \ gd \ libjpeg libjpeg-devel \ libpng libpng-devel \ freetype freetype-devel \ libxml2 libxml2-devel \ zlib zlib-devel \ curl curl-devel \ openssl openssl-devel cd /opt tar jxvf php-7.1.10.tar.bz2 cd /opt/php-7.1.10/ ./configure \ --prefix=/usr/local/php7 \ --with-apxs2=/usr/local/httpd/bin/apxs \ --with-mysql-sock=/usr/local/mysql/mysql.sock \ --with-config-file-path=/usr/local/php7 \ --with-mysqli \ --with-zlib \ --with-curl \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-openssl \ --enable-mbstring \ --enable-xml \ --enable-session \ --enable-ftp \ --enable-pdo \ --enable-tokenizer \ --enable-zip make -j 4 && make install cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini #在测试环境时使用php.ini-development文件,而在生产环境时使用php.ini-production文件 sed -i.bak -e "1170 s|.*|mysqli.default_socket = /usr/local/mysql/mysql.sock|" -e "939 s|.*|date.timezone = Asia/Shanghai|" /usr/local/php7/php.ini ln -s /usr/local/php7/bin/* /usr/local/bin/ sed -i.bak -e "255 s/.*/DirectoryIndex index.html index.php/" -e "393c AddType application/x-httpd-php .php\nAddType application/x-httpd-php-source .phps" /etc/httpd.conf rm -rf /usr/local/httpd/htdocs/index.html echo "<?php phpinfo(); ?>" > /usr/local/httpd/htdocs/index.php systemctl restart httpd.service /usr/bin/expect <<EOF spawn mysql -u root -p expect "Enter password" {send "abc123\r"} expect "mysql" {send "CREATE DATABASE bbs;\r"} expect "mysql" {send "GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';\r"} expect "mysql" {send "flush privileges;\r"} expect "mysql" {send "quit\r"} expect eof EOF unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis cd /opt/dis/dir_SC_UTF8/ cp -r upload/ /usr/local/httpd/htdocs/bbs cd /usr/local/httpd/htdocs/bbs chown -R daemon ./config chown -R daemon ./data chown -R daemon ./uc_client chown -R daemon ./uc_server/data #!/bin/bash