One place for hosting & domains

      Run a Small Business? Here are 8 Ways to Manage Your Stress


      There are plenty of perks to owning your business — like being the boss, for one. You get to see your own plans and dreams come to life. And you can set the company track exactly as you see fit. But the downside to running a small business? All of the stress that comes with it. That’s why learning to manage stress is crucial for small biz owners.

      “Managing stress is important as a business owner because typically, we tend to be sole proprietors or have few employees,” says Amanda Pratt MSW, LCSW, CPLC, The Chronic Illness Therapist, Imagine Life Therapy. “This means that if we burn out, it can ultimately slow business progress or momentum and when we aren’t well, our businesses can’t be well. We also know that if we cope poorly with stress, we tend to have worse physical and mental health outcomes overall, so business owner or not, this is an area that I feel should be a top priority for all of us.”

      Reducing stress should always be at the top of your to-do list to keep you sane — and your company healthy, too. “That’s why it’s important not to feel guilty for stepping back or prioritizing some ‘me’ time,” says Poppy Greenwood, mental health advocate, serial entrepreneur and co-founder of female entrepreneur support platform Meyvnn.

      Luckily, there are plenty of small business stress management techniques that will help take away the tension and anxiety of your work. Give these tactics a try to manage your stress levels.

      8 Ways to Handle Small Biz Stress

      Stressed small business owner.

      1. Recognize What’s Going Well

      “This is one of the first things I will point out to clients — it’s just as important to recognize what’s going well (if not more so) as it is to recognize where things aren’t going so well,” Pratt says.

      “Strategies that work best for us tend to play off our strengths. It’s also good to take inventory of areas of coping where we tend to have more engaged or active responses to stress (versus disengaged responses) and can inform our future attempts at other areas of stress management. We all have habits that come more naturally to us that are healthy, and I believe these are the strategies we should tap into first to address when creating a stress management plan.”

      Plus, when you consider what’s going right with your business, that instantly puts you in a positive mindset, which makes it much easier to combat stress. “Taking stock of things that have gone well helps you put into perspective the change you are affecting and the growth that you have achieved,” Greenwood says. “Feeling that you’re making progress, no matter how small, is one of the best ways to relax. It helps you to recognize you’re on a journey, and that your work towards whatever goal you have is pushing you forwards.

      “It also just makes you feel more organized,” Greenwood says. “Being able to identify where things are working or are not makes you feel like you have control over what is happening, in what can feel like the chaos of running a business.”

      Focusing on the good things about your business also keeps your mind in the present. “When you’re stressed, your brain tells you that you have to stay vigilant,” says Drema Dial, Ph.D., psychologist and life coach. “Your brain goes into hyperdrive with all the things that could be going wrong, will go wrong, might have already gone wrong, and how will you fix it! This is one way our brain uses to keep us locked into familiar routines. This is precisely why it’s imperative to break this cycle, which keeps us chained to unhealthy coping behaviors and keeps your stress level high.”

      2. Identify Your Stressors

      “Identifying your stressors is vital to be able to tackle them,” Greenwood says. “Stress usually comes from a problem you haven’t yet started to solve or are having trouble solving. I think the best way to identify stressors is to take a step back. When you’re an entrepreneur, you’re constantly working and adjusting and testing to grow. Being in that kind of intense mindset all day long can really constrict a wider perspective you need to really pinpoint the areas that are causing you stress and how best to tackle them. Once you’ve identified what is causing you stress, you are much more able to work out how to deal with it. And even just identifying what is causing you stress can help alleviate some of it.”

      Remember that people respond to stress in their own unique way. “Self-awareness is key here because everyone is different,” says Mike McDonnell, international speaker, serial entrepreneur, global brand co-owner and podcaster. Once you know what stresses you out, you can delegate those tasks to others. If that’s not an option, knowing that a particular part of the job triggers anxiety can help you prepare to tackle it and just take a deep breath before going in. Over time, you can work on changing your response to the stressor.

      “We can do this through practicing mindfulness techniques to open our awareness to our body sensations, thoughts, and behaviors,” Pratt says. “We can also self-monitor through journaling or tracking mood states, symptoms and thought habits. And while it’s good to identify stressors, it’s even more important to identify our perceptions and responses to these stressors. Research shows us that it matters less what the stressor is and more how we respond to the stressor.”

      3. Build a Solid Schedule

      “Structure is important because the more we plan, the less we have to actively anticipate what might happen,” Pratt says. “Planning helps us have a greater sense of self-efficacy or confidence in our ability to handle whatever might come up.”

      When you have a regular routine, you know what to expect at work, and that gives you a sense of peace and control, making it easier to keep stress at bay. If you know in advance that you have a difficult item to cross off your to-do list, tackle it first thing in the morning to avoid that sense of dread. Plus, you’ll feel accomplished and ready to conquer whatever else comes your way.

      “Your body also likes a routine — it’s good for your circadian rhythm, which is effectively your internal body clock that can dictate things like when you feel tired or energized and can really impact your ability to focus,” Greenwood says. “For example, I know my energy and concentration dip around 3 p.m. So, in my routine around that time, I usually have a workout scheduled that gives me some time away to re-energize.”

      A common complaint from small business owners is that there are never enough hours in the day. “Usually when we delve into this issue, the problem is not a lack of time but a lack of a schedule,” Dial says. “A schedule allows a person to plan, to anticipate, and helps keep life organized. I recommend that all activities go onto a schedule, even play time!”

      4. Prioritize Your Time

      There’s a reason “self-care” has become such a buzzword — we’ve come to realize just how crucial it is to carve out time for ourselves to keep a healthy mental state. Looking after yourself is key to keeping stress under control.

      “Prioritizing ‘me time’ is really important because it is so easy to get caught up in what you’re doing, you can really forget about yourself and who you are — separate from your business,” Greenwood says. “Taking time for yourself, or using it to go out with friends and family, is often what re-affirms your belief in what you’re doing. It’s really important to not lose yourself within your business, because that, in the worst case scenario, then can lead to your business itself losing its way.”

      As a small business owner, it’s all too easy to fall into the trap of always being on the clock. Just as you schedule time for certain tasks you need to get done, you should schedule free time. “I teach clients to see their downtime as beneficial to creativity and efficiency because they tend to work better after taking a break,” Dial says. “Taking a break allows the brain to take in new information and to generate creativity.”

      5. Learn to Say ‘No’

      “When you’re starting out, you may not have the luxury of opportunities flying at you, so you say yes to everything,” McDonnell says. “But eventually you focus on your mission and ask yourself, ‘Will this help me get there?’ before deciding yes or no.”

      Of course, saying no can be really tough. But it’s important to remember your value and that you have limited time. “Instead of thinking you may offend the other person, it’s an opportunity to show them that when you decide to do something, you really value what you’re doing and you’re doing it on your terms,” Greenwood says.

      Otherwise, taking on more than you can handle is the fastest way to fall into a stress trap. “It’s important to learn that setting boundaries is necessary to safeguard small business owners’ well-being, their time, and to protect their business,” Dial says. “When approached with a request, the small business owner should ask themselves the following: ‘1. Is this something I want to do? 2. Do I have time to do it? 3. What is its importance level, and will it fit it into my schedule?’”

      Saying no is also key to setting boundaries. “When we don’t set boundaries, we end up feeling taken advantage of, burned out, stressed out, and end up as people pleasers, workaholics, isolated, or feeling misunderstood,” Pratt says. “Simply stated: Boundaries are one of the best things you can do for your physical and mental health and wellness.”

      6.Delegate or Outsource Tasks

      When you’re used to being the boss, it can be hard to let go and give up control. But as any small business owner knows, you can’t do it all. And if you’re trying to, then you’re probably not doing a good job at every single thing. That’s why learning how to delegate or outsource certain parts of the biz is a foundation for being successful.

      For example, do you struggle with Facebook but love working face-to-face with clients? Hiring a social media manager might free you up to do just that. Figure out how you want to spend your time — and what you’d rather avoid.

      In the end, outsourcing allows you to grow your company. “It’s important early on to recognize where your weaknesses are, so that you can hand over those areas to other people who do them much better,” Greenwood says. “Doing this can also relieve so much stress, not having a task hang over you that you know you need to do but that you struggle with and find time-consuming.”

      7. Choose Your Tools Wisely

      Work tools and software are meant to make your job easier — not harder. But if you’re spending more time learning how to use them than actually using them, it’s not doing you any favors. “It’s important to choose tools wisely, because they are meant to be the things that take away stress and help with tasks instead of adding to the problem,” Greenwood says.

      Opting for reliable small business appsweb management tools, and hosting services will always pay off in the end. Imagine if your business’ website went down? That’s why it’s worth using DreamHost hosting and WordPress to have one less thing to worry about.

      “Test out different software until you find the one that takes your stress away so you can benefit fully from it,” McDonnell says.

      Shared Hosting That Powers Your Purpose

      We make sure your website is fast, secure and always up so your visitors trust you.

      8. Unplug During Your Off-time

      “You’re not a robot,” Greenwood says. “You can’t work all the time and expect to maintain the same level of productivity and efficiency. You need to replenish your energy levels, and not just physically but mentally, emotionally, and spiritually. When you’re working on your business, you want to be present and in the moment. That would be difficult if you’re unable to unplug in your off time and feel a conflict between your work life and your personal life.”

      As a small business owner, you probably feel tied to your phone, but you need time away from answering emails and checking in with customers. “Unplugging and doing a digital detox allows parts of your brain to rest,” Dial says. “Reading, watching TV, going for a walk, and talking with others are all great ways to engage a different part of your brain. Make sure you take time for activities you find enjoyable. It’s essential to combat stress by seeking out experiences that will help restore you.”

      It’s especially important to power down your devices and avoid blue light, which can keep you awake, at least an hour before bedtime. Plus, you won’t have to worry about an email keeping you up that night. You’ll sleep better so you can be rested and alert for the next day of tending to your business.

      Breathe In and Out

      It’s no secret that running a small business is one of the most challenging (and stressful) things you’ll ever take on. But it’s also one of the most rewarding! So tell us: how do you manage your stress as a small-biz owner? What keeps you fired up as you “Rise and Grind?” Connect with us on Twitter and let us know your thoughts!





      Source link

      How To Install and Use ClickHouse on CentOS 7


      The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program.

      Introduction

      ClickHouse is an open-source, column-oriented analytics database created by Yandex for OLAP and big data use cases. ClickHouse’s support for real-time query processing makes it suitable for applications that require sub-second analytical results. ClickHouse’s query language is a dialect of SQL that enables powerful declarative querying capabilities while offering familiarity and a smaller learning curve for the end user.

      Column-oriented databases store records in blocks grouped by columns instead of rows. By not loading data for columns absent in the query, column-oriented databases spend less time reading data while completing queries. As a result, these databases can compute and return results much faster than traditional row-based systems for certain workloads, such as OLAP.

      Online Analytics Processing (OLAP) systems allow for organizing large amounts of data and performing complex queries. They are capable of managing petabytes of data and returning query results quickly. In this way, OLAP is useful for work in areas like data science and business analytics.

      In this tutorial, you’ll install the ClickHouse database server and client on your machine. You’ll use the DBMS for typical tasks and optionally enable remote access from another server so that you’ll be able to connect to the database from another machine. Then you’ll test ClickHouse by modeling and querying example website-visit data.

      Prerequisites

      • One CentOS 7 server with a sudo enabled non-root user and firewall setup. You can follow the initial server setup tutorial to create the user and this tutorial to set up the firewall.
      • (Optional) A secondary CentOS 7 server with a sudo enabled non-root user and firewall setup. You can follow the initial server setup tutorial and the additional setup tutorial for the firewall.

      Step 1 — Installing ClickHouse

      In this section, you will install the ClickHouse server and client programs using yum.

      First, SSH into your server by running:

      Install the base dependencies by executing:

      • sudo yum install -y pygpgme yum-utils

      The pygpgme packages is used for adding and verifying GPG signatures while the yum-utils allows easy management of source RPMs.

      Altinity, a ClickHouse consulting firm, maintains a YUM repository that has the latest version of ClickHouse. You'll add the repository's details to securely download validated ClickHouse packages by creating the file. To check the package contents, you can inspect the sources from which they are built at this Github project.

      Create the repository details file by executing:

      • sudo vi /etc/yum.repos.d/altinity_clickhouse.repo

      Next, add the following contents to the file:

      /etc/yum.repos.d/altinity_clickhouse.repo

      [altinity_clickhouse]
      name=altinity_clickhouse
      baseurl=https://packagecloud.io/altinity/clickhouse/el/7/$basearch
      repo_gpgcheck=1
      gpgcheck=0
      enabled=1
      gpgkey=https://packagecloud.io/altinity/clickhouse/gpgkey
      sslverify=1
      sslcacert=/etc/pki/tls/certs/ca-bundle.crt
      metadata_expire=300
      
      [altinity_clickhouse-source]
      name=altinity_clickhouse-source
      baseurl=https://packagecloud.io/altinity/clickhouse/el/7/SRPMS
      repo_gpgcheck=1
      gpgcheck=0
      enabled=1
      gpgkey=https://packagecloud.io/altinity/clickhouse/gpgkey
      sslverify=1
      sslcacert=/etc/pki/tls/certs/ca-bundle.crt
      metadata_expire=300
      

      Now that you've added the repositories, enable them with the following command:

      • sudo yum -q makecache -y --disablerepo='*' --enablerepo='altinity_clickhouse'

      The -q flag tells the command to run in quiet mode. The makecache command makes available the packages specified in the --enablerepo flag.

      On execution, you'll see output similar to the following:

      Output

      Importing GPG key 0x0F6E36F6: Userid : "https://packagecloud.io/altinity/clickhouse (https://packagecloud.io/docs#gpg_signing) <[email protected]>" Fingerprint: 7001 38a9 6a20 6b22 bf28 3c06 ed26 58f3 0f6e 36f6 From : https://packagecloud.io/altinity/clickhouse/gpgkey

      The output confirms it has successfully verified and added the GPG key.

      The clickhouse-server and clickhouse-client packages will now be available for installation. Install them with:

      • sudo yum install -y clickhouse-server clickhouse-client

      You've installed the ClickHouse server and client successfully. You're now ready to start the database service and ensure that it's running correctly.

      Step 2 — Starting the Service

      The clickhouse-server package that you installed in the previous section creates a systemd service, which performs actions such as starting, stopping, and restarting the database server. systemd is an init system for Linux to initialize and manage services. In this section you'll start the service and verify that it is running successfully.

      Start the clickhouse-server service by running:

      • sudo service clickhouse-server start

      You will see output similar to the following:

      Output

      Start clickhouse-server service: Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/ DONE

      To verify that the service is running successfully, execute:

      • sudo service clickhouse-server status

      It will print an output similar to the following which denotes that the server is running properly:

      Output

      clickhouse-server service is running

      You have successfully started the ClickHouse server and will now be able to use the clickhouse-client CLI program to connect to the server.

      Step 3 — Creating Databases and Tables

      In ClickHouse, you can create and delete databases by executing SQL statements directly in the interactive database prompt. Statements consist of commands following a particular syntax that tell the database server to perform a requested operation along with any data required. You create databases by using the CREATE DATABASE table_name syntax. To create a database, first start a client session by running the following command:

      • clickhouse-client --multiline

      This command will log you into the client prompt where you can run ClickHouse SQL statements to perform actions such as:

      • Creating, updating, and deleting databases, tables, indexes, partitions, and views.

      • Executing queries to retrieve data that is optionally filtered and grouped using various conditions.

      The --multiline flag tells the CLI to allow entering queries that span multiple lines.

      In this step, with the ClickHouse client ready for inserting data, you're going to create a database and table. For the purposes of this tutorial, you'll create a database named test, and inside that you'll create a table named visits that tracks website-visit durations.

      Now that you're inside the ClickHouse command prompt, create your test database by executing:

      You'll see the following output that shows that you have created the database:

      Output

      CREATE DATABASE test Ok. 0 rows in set. Elapsed: 0.003 sec.

      A ClickHouse table is similar to tables in other relational databases; it holds a collection of related data in a structured format. You can specify columns along with their types, add rows of data, and execute different kinds of queries on tables.

      The syntax for creating tables in ClickHouse follows this example structure:

      CREATE TABLE table_name
      (
          column_name1 column_type [options],
          column_name2 column_type [options],
          ...
      ) ENGINE = engine
      

      The table_name and column_name values can be any valid ASCII identifiers. ClickHouse supports a wide range of column types; some of the most popular are:

      • UInt64: used for storing integer values in the range 0 to 18446744073709551615.

      • Float64: used for storing floating point numbers such as 2039.23, 10.5, etc.

      • String: used for storing variable length characters. It does not require a max length attribute since it can store arbitrary lengths.

      • Date: used for storing dates that follow the YYYY-MM-DD format.

      • DateTime: used for storing dates coupled with time and follows the YYYY-MM-DD HH:MM:SS format.

      After the column definitions, you specify the engine used for the table. In ClickHouse, Engines determine the physical structure of the underlying data, the table's querying capabilities, its concurrent access modes, and support for indexes. Different engine types are suitable for different application requirements. The most commonly used and widely applicable engine type is MergeTree.

      Now that you have an overview of table creation, you'll create a table. Start by confirming the database you'll be modifying:

      You will see the following output showing that you have switched to the test database from the default database:

      Output

      USE test Ok. 0 rows in set. Elapsed: 0.001 sec.

      The remainder of this guide will assume that you are executing statements within this database's context.

      Create your visits table by running this command:

      • CREATE TABLE visits (
      • id UInt64,
      • duration Float64,
      • url String,
      • created DateTime
      • ) ENGINE = MergeTree()
      • PRIMARY KEY id
      • ORDER BY id;

      Here's a breakdown of what the command does. You create a table named visits that has four columns:

      • id: The primary key column. Similarly to other RDBMS systems, a primary key column in ClickHouse uniquely identifies a row; each row should have a unique value for this column.

      • duration: A float column used to store the duration of each visit in seconds. float columns can store decimal values such as 12.50.

      • url: A string column that stores the URL visited, such as http://example.com.

      • created: A date and time column that tracks when the visit occurred.

      After the column definitions, you specify MergeTree as the storage engine for the table. The MergeTree family of engines is recommended for production databases due to its optimized support for large real-time inserts, overall robustness, and query support. Additionally, MergeTree engines support sorting of rows by primary key, partitioning of rows, and replicating and sampling data.

      If you intend to use ClickHouse for archiving data that is not queried often or for storing temporary data, you can use the Log family of engines to optimize for that use-case.

      After the column definitions, you'll define other table-level options. The PRIMARY KEY clause sets id as the primary key column and the ORDER BY clause will store values sorted by the id column. A primary key uniquely identifies a row and is used for efficiently accessing a single row and efficient colocation of rows.

      On executing the create statement, you will see the following output:

      Output

      CREATE TABLE visits ( id UInt64, duration Float64, url String, created DateTime ) ENGINE = MergeTree() PRIMARY KEY id ORDER BY id Ok. 0 rows in set. Elapsed: 0.010 sec.

      In this section, you've created a database and a table to track website-visits data. In the next step, you'll insert data into the table, update existing data, and delete that data.

      Step 4 — Inserting, Updating, and Deleting Data and Columns

      In this step, you'll use your visits table to insert, update, and delete data. The following command is an example of the syntax for inserting rows into a ClickHouse table:

      INSERT INTO table_name VALUES (column_1_value, column_2_value, ....);
      

      Now, insert a few rows of example website-visit data into your visits table by running each of the following statements:

      • INSERT INTO visits VALUES (1, 10.5, 'http://example.com', '2019-01-01 00:01:01');
      • INSERT INTO visits VALUES (2, 40.2, 'http://example1.com', '2019-01-03 10:01:01');
      • INSERT INTO visits VALUES (3, 13, 'http://example2.com', '2019-01-03 12:01:01');
      • INSERT INTO visits VALUES (4, 2, 'http://example3.com', '2019-01-04 02:01:01');

      You'll see the following output repeated for each insert statement:

      Output

      INSERT INTO visits VALUES Ok. 1 rows in set. Elapsed: 0.004 sec.

      The output for each row shows that you've inserted it successfully into the visits table.

      Now you'll add an additional column to the visits table. When adding or deleting columns from existing tables, ClickHouse supports the ALTER syntax.

      For example, the basic syntax for adding a column to a table is as follows:

      ALTER TABLE table_name ADD COLUMN column_name column_type;
      

      Add a column named location that will store the location of the visits to a website by running the following statement:

      • ALTER TABLE visits ADD COLUMN location String;

      You'll see output similar to the following:

      Output

      ALTER TABLE visits ADD COLUMN location String Ok. 0 rows in set. Elapsed: 0.014 sec.

      The output shows that you have added the location column successfully.

      As of version 19.4.3, ClickHouse doesn't support updating and deleting individual rows of data due to implementation constraints. ClickHouse has support for bulk updates and deletes, however, and has a distinct SQL syntax for these operations to highlight their non-standard usage.

      The following syntax is an example for bulk updating rows:

      ALTER TABLE table_name UPDATE  column_1 = value_1, column_2 = value_2 ...  WHERE  filter_conditions;
      

      You'll run the following statement to update the url column of all rows that have a duration of less than 15. Enter it into the database prompt to execute:

      • ALTER TABLE visits UPDATE url = 'http://example2.com' WHERE duration < 15;

      The output of the bulk update statement will be as follows:

      Output

      ALTER TABLE visits UPDATE url = 'http://example2.com' WHERE duration < 15 Ok. 0 rows in set. Elapsed: 0.003 sec.

      The output shows that your update query completed successfully. The 0 rows in set in the output denotes that the query did not return any rows; this will be the case for any update and delete queries.

      The example syntax for bulk deleting rows is similar to updating rows and has the following structure:

      ALTER TABLE table_name DELETE WHERE filter_conditions;
      

      To test deleting data, run the following statement to remove all rows that have a duration of less than 5:

      • ALTER TABLE visits DELETE WHERE duration < 5;

      The output of the bulk delete statement will be similar to:

      Output

      ALTER TABLE visits DELETE WHERE duration < 5 Ok. 0 rows in set. Elapsed: 0.003 sec.

      The output confirms that you have deleted the rows with a duration of less than five seconds.

      To delete columns from your table, the syntax would follow this example structure:

      ALTER TABLE table_name DROP COLUMN column_name;
      

      Delete the location column you added previously by running the following:

      • ALTER TABLE visits DROP COLUMN location;

      The DROP COLUMN output confirming that you have deleted the column will be as follows:

      Output

      ALTER TABLE visits DROP COLUMN location String Ok. 0 rows in set. Elapsed: 0.010 sec.

      Now that you've successfully inserted, updated, and deleted rows and columns in your visits table, you'll move on to query data in the next step.

      Step 5 — Querying Data

      ClickHouse's query language is a custom dialect of SQL with extensions and functions suited for analytics workloads. In this step, you'll run selection and aggregation queries to retrieve data and results from your visits table.

      Selection queries allow you to retrieve rows and columns of data filtered by conditions that you specify, along with options such as the number of rows to return. You can select rows and columns of data using the SELECT syntax. The basic syntax for SELECT queries is:

      SELECT func_1(column_1), func_2(column_2) FROM table_name WHERE filter_conditions row_options;
      

      Execute the following statement to retrieve url and duration values for rows where the url is http://example.com:

      • SELECT url, duration FROM visits WHERE url = 'http://example2.com' LIMIT 2;

      You will see the following output:

      Output

      SELECT url, duration FROM visits WHERE url = 'http://example2.com' LIMIT 2 ┌─url─────────────────┬─duration─┐ │ http://example2.com │ 10.5 │ └─────────────────────┴──────────┘ ┌─url─────────────────┬─duration─┐ │ http://example2.com │ 13 │ └─────────────────────┴──────────┘ 2 rows in set. Elapsed: 0.013 sec.

      The output has returned two rows that match the conditions you specified. Now that you've selected values, you can move to executing aggregation queries.

      Aggregation queries are queries that operate on a set of values and return single output values. In analytics databases, these queries are run frequently and are well optimized by the database. Some aggregate functions supported by ClickHouse are:

      • count: returns the count of rows matching the conditions specified.

      • sum: returns the sum of selected column values.

      • avg: returns the average of selected column values.

      Some ClickHouse-specific aggregate functions include:

      • uniq: returns an approximate number of distinct rows matched.

      • topK: returns an array of the most frequent values of a specific column using an approximation algorithm.

      To demonstrate the execution of aggregation queries, you'll calculate the total duration of visits by running the sum query:

      • SELECT SUM(duration) FROM visits;

      You will see output similar to the following:

      Output

      SELECT SUM(duration) FROM visits ┌─SUM(duration)─┐ │ 63.7 │ └───────────────┘ 1 rows in set. Elapsed: 0.010 sec.

      Now, calculate the top two URLs by executing:

      • SELECT topK(2)(url) FROM visits;

      You will see output similar to the following:

      Output

      SELECT topK(2)(url) FROM visits ┌─topK(2)(url)──────────────────────────────────┐ │ ['http://example2.com','http://example1.com'] │ └───────────────────────────────────────────────┘ 1 rows in set. Elapsed: 0.010 sec.

      Now that you have successfully queried your visits table, you'll delete tables and databases in the next step.

      Step 6 — Deleting Tables and Databases

      In this section, you'll delete your visits table and test database.

      The syntax for deleting tables follows this example:

      DROP TABLE table_name;
      

      To delete the visits table, run the following statement:

      You will see the following output declaring that you've deleted the table successfully:

      Output

      DROP TABLE visits Ok. 0 rows in set. Elapsed: 0.005 sec.

      You can delete databases using the DROP database table_name syntax. To delete the test database, execute the following statement:

      The resulting output shows that you've deleted the database successfully:

      Output

      DROP DATABASE test Ok. 0 rows in set. Elapsed: 0.003 sec.

      You've deleted tables and databases in this step. Now that you've created, updated, and deleted databases, tables, and data in your ClickHouse instance, you'll enable remote access to your database server in the next section.

      Step 7 — Setting Up Firewall Rules (Optional)

      If you intend to only use ClickHouse locally with applications running on the same server, or do not have a firewall enabled on your server, you don't need to complete this section. If instead, you'll be connecting to the ClickHouse database server remotely, you should follow this step.

      Currently your server has a firewall enabled that disables your public IP address accessing all ports. You'll complete the following two steps to allow remote access:

      • Add a firewall rule allowing incoming connections to port 8123, which is the HTTP port that ClickHouse server runs.

      If you are inside the database prompt, exit it by typing CTRL+D.

      Edit the configuration file by executing:

      • sudo vi /etc/clickhouse-server/config.xml

      Then uncomment the line containing <!-- <listen_host>0.0.0.0</listen_host> -->, like the following file:

      /etc/clickhouse-server/config.xml

      
      ...
       <interserver_http_host>example.yandex.ru</interserver_http_host>
          -->
      
          <!-- Listen specified host. use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere. -->
          <!-- <listen_host>::</listen_host> -->
          <!-- Same for hosts with disabled ipv6: -->
          <listen_host>0.0.0.0</listen_host>
      
          <!-- Default values - try listen localhost on ipv4 and ipv6: -->
          <!--
          <listen_host>::1</listen_host>
          <listen_host>127.0.0.1</listen_host>
          -->
      ...
      
      

      Save the file and exit vi. For the new configuration to apply restart the service by running:

      • sudo service clickhouse-server restart

      You will see the following output from this command:

      Output

      Stop clickhouse-server service: DONE Start clickhouse-server service: Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/ DONE

      Add the remote server's IP to zone called public:

      • sudo firewall-cmd --permanent --zone=public --add-source=second_server_ip/32

      ClickHouse's server listens on port 8123 for HTTP connections and port 9000 for connections from clickhouse-client. Allow access to both ports for your second server's IP address with the following command:

      • sudo firewall-cmd --permanent --zone=public --add-port=8123/tcp
      • sudo firewall-cmd --permanent --zone=public --add-port=9000/tcp

      You will see the following output for both commands that shows that you've enabled access to both ports:

      Output

      success

      Now that you have added the rules, reload the firewall for the changes to take effect:

      • sudo firewall-cmd --reload

      This command will output a success message as well. ClickHouse will now be accessible from the IP that you added. Feel free to add additional IPs such as your local machine's address if required.

      To verify that you can connect to the ClickHouse server from the remote machine, first follow the steps in Step 1 of this tutorial on the second server and ensure that you have the clickhouse-client installed on it.

      Now that you have logged into the second server, start a client session by executing:

      • clickhouse-client --host your_server_ip --multiline

      You will see the following output that shows that you have connected successfully to the server:

      Output

      ClickHouse client version 19.4.3. Connecting to your_server_ip:9000 as user default. Connected to ClickHouse server version 19.4.3 revision 54416. hostname :)

      In this step, you've enabled remote access to your ClickHouse database server by adjusting your firewall rules.

      Conclusion

      You have successfully set up a ClickHouse database instance on your server and created a database and table, added data, performed queries, and deleted the database. Within ClickHouse's documentation you can read about their benchmarks against other open-source and commercial analytics databases and general reference documents. Further features ClickHouse offers includes distributed query processing across multiple servers to improve performance and protect against data loss by storing data over different shards.



      Source link

      How To Install Go and Set Up a Local Programming Environment on Windows 10


      Introduction

      Go is a programming language that was born out of frustration at Google. Developers continually had to pick a language that executed efficiently but took a long time to compile, or to pick a language that was easy to program but ran inefficiently in production. Go was designed to have all three available at the same time: fast compilation, ease of programming, and efficient execution in production.

      While Go is a versatile programming language that can be used for many different programming projects, it’s particularly well suited for networking/distributed systems programs, and has earned a reputation as “the language of the cloud”. It focuses on helping the modern programmer do more with a strong set of tooling, removing debates over formatting by making the format part of the language specification, as well as making deployment easy by compiling to a single binary. Go is easy to learn, with a very small set of keywords, which makes it a great choice for beginners and experienced developers alike.

      This tutorial will guide you through installing Go on your local Windows 10 machine and setting up a programming environment via the command line.

      Prerequisites

      You will need a Windows 10 machine with administrative access that is connected to the internet.

      Step 1 — Opening and Configuring PowerShell

      You’ll be completing most of the installation and setup on a command-line interface, which is a non-graphical way to interact with your computer. That is, instead of clicking on buttons, you’ll be typing in text and receiving feedback from your computer through text as well. The command line, also known as a shell, can help you modify and automate many of the tasks you do on a computer every day, and is an essential tool for software developers.

      PowerShell is a program from Microsoft that provides a command-line shell interface. Administrative tasks are performed by running cmdlets, pronounced command-lets, which are specialized classes of the .NET software framework that can carry out operations. Open-sourced in August 2016, PowerShell is now available across platforms, for both Windows and UNIX systems (including Mac and Linux).

      To find Windows PowerShell, you can right-click on the Start menu icon on the lower left-hand corner of your screen. When the menu pops up, click on Search, and then type PowerShell into the search bar. When you are presented with options, right-click on Windows PowerShell from the Desktop app. For the purposes of this tutorial, select Run as Administrator. When you are prompted with a dialog box that asks Do you want to allow this app to make changes to your PC? click on Yes.

      Once you do this, you’ll see a text-based interface that has a string of words that looks like this:

      Windows 10 PowerShell

      Switch out of the system folder by typing the following command:

      You'll then be in a home directory such as PS C:Userssammy.

      To continue with the installation process, you must first set up permissions through PowerShell. Configured to run in the most secure mode by default, there are a few levels of permissions that you can set up as an administrator:

      • Restricted is the default execution policy. Under this mode you will not be able to run scripts, and PowerShell will work only as an interactive shell.
      • AllSigned will enable you to run all scripts and configuration files that are signed by a trusted publisher, meaning that you could potentially open your machine up to the risk of running malicious scripts that happen to be signed by a trusted publisher.
      • RemoteSigned will let you run scripts and configuration files downloaded from the internet signed by trusted publishers, again opening your machine up to vulnerabilities if these trusted scripts are actually malicious.
      • Unrestricted will run all scripts and configuration files downloaded from the internet as soon as you confirm that you understand that the file was downloaded from the internet. In this case no digital signature is required, so you could be opening your machine up to the risk of running unsigned and potentially malicious scripts downloaded from the internet.

      In this tutorial you will use the RemoteSigned execution policy to set the permissions for the current user. This will allow the PowerShell to accept trusted scripts without making the permissions as broad as they would be with an Unrestricted permission. Enter the following in PowerShell:

      • Set-ExecutionPolicy -Scope CurrentUser

      PowerShell will then prompt you to provide an execution policy. Enter the following to use RemoteSigned:

      Once you press ENTER, you’ll be asked to confirm the change to the execution policy. Type the letter y to allow the changes to take effect. You can confirm that this worked by asking for the current permissions across the machine:

      • Get-ExecutionPolicy -List

      You should receive output that looks something like this:

      Output

      Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser RemoteSigned LocalMachine Undefined

      This confirms that the current user can run trusted scripts downloaded from the internet. You can now move on to downloading the files we will need to set up our Go programming environment.

      Step 2 — Installing the Package Manager Chocolatey

      A package manager is a collection of software tools that work to automate installation processes. This includes the initial installation, upgrading and configuring of software, and removing software as needed. They keep software installations in a central location and can maintain all software packages on the system in formats that are commonly used.

      Chocolatey is a command-line package manager built for Windows that works like apt-get does on Linux. Available in an open-source version, Chocolatey will help you quickly install applications and tools. You will be using it to download what you need for your development environment.

      Before installing the script, read it to confirm that you are happy with the changes it will make to your machine. To do this, use the .NET scripting framework to download and display the Chocolatey script within the terminal window.

      Start by creating a WebClient object called $script that shares internet connection settings with Internet Explorer:

      • $script = New-Object Net.WebClient

      Take a look at the available options by piping the $script object with | to the Get-Member class:

      This will return all members (properties and methods) of this WebClient object:

      Snippet of Output

      . . . DownloadFileAsync Method void DownloadFileAsync(uri address, string fileName), void DownloadFileAsync(ur... DownloadFileTaskAsync Method System.Threading.Tasks.Task DownloadFileTaskAsync(string address, string fileNa... DownloadString Method string DownloadString(string address), string DownloadString(uri address) #method we will use DownloadStringAsync Method void DownloadStringAsync(uri address), void DownloadStringAsync(uri address, Sy... DownloadStringTaskAsync Method System.Threading.Tasks.Task[string] DownloadStringTaskAsync(string address), Sy… . . .

      Looking over the output, you can identify the DownloadString method used to display the script and signature in the PowerShell window. Use this method to inspect the script:

      • $script.DownloadString("https://chocolatey.org/install.ps1")

      After inspecting the script, install Chocolatey by typing the following into PowerShell:

      • iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

      The cmdlet iwr, or Invoke-WebRequest, allows you to extract data from the web. This will pass the script to iex, or the Invoke-Expression cmdlet, which will execute the contents of the script and run the installation for the Chocolatey package manager.

      Allow PowerShell to install Chocolatey. Once it is fully installed, you can begin installing additional tools with the choco command.

      If you need to upgrade Chocolatey at any time in the future, run the following command:

      With the package manager installed, you can install the rest of what you need for the Go programming environment.

      Step 3 — Installing the Text Editor Nano (Optional)

      In this step, you are going to install nano, a text editor that uses a command-line interface. You can use nano to write programs directly within PowerShell. This is not a compulsory step, as you can also use a text editor with a graphical user interface such as Notepad. This tutorial recommends using nano, as it will help accustom you to using PowerShell.

      Use Chocolatey to install nano:

      The -y flag automatically confirms that you want to run the script without being prompted for confirmation.

      Once nano is installed, you can use the nano command to create new text files. You will use it later in this tutorial to write your first Go program.

      Step 4 — Installing Go

      Just like you did with nano in the previous step, you will use Chocolatey to install Go:

      Note: Because go is such a small word, it has become common to use golang as a term for installing packages and when searching the internet for Go-related articles. The term Golang was born from the domain for Go, which is golang.org.

      PowerShell will now install Go, generating output within PowerShell during that process. Once the install is completed, you should see the following output:

      Output

      Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type `refreshenv`). The install of golang was successful. Software installed as 'msi', install location is likely default. Chocolatey installed 1/1 packages. See the log for details (C:ProgramDatachocolateylogschocolatey.log).

      With the installation finished, you’ll now confirm that Go is installed. To see the changes, close and re-open PowerShell as an Administrator, then check the version of Go available on your local machine:

      You'll receive output similar to the following:

      Output

      go version go1.12.1 windows/amd643.7.0

      Once Go is installed, you can set up a workspace for your development projects.

      Step 5 — Creating Your Go Workspace

      Now that you have Chocolatey, nano, and Go installed, you can create your programming workspace.

      The Go workspace will contain two directories at its root:

      • src: The directory that contains Go source files. A source file is a file that you write using the Go programming language. Source files are used by the Go compiler to create an executable binary file.
      • bin: The directory that contains executables built and installed by the Go tools. Executables are binary files that run on your system and execute tasks. These are typically the programs compiled by your source code or another downloaded Go source code.

      The src subdirectory may contain multiple version control repositories (such as Git, Mercurial, and Bazaar). You will see directories like github.com or golang.org when your program imports third party libraries. If you are using a code repository like github.com, you will also put your projects and source files under that directory. This allows for a canonical import of code in your project. Canonical imports are imports that reference a fully qualified package, such as github.com/digitalocean/godo.

      Here is what a typical workspace may look like:

      .
      ├── bin
      │   ├── buffalo                                      # command executable
      │   ├── dlv                                          # command executable
      │   └── packr                                        # command executable
      └── src
          └── github.com
              └── digitalocean
                  └── godo
                      ├── .git                            # Git repository metadata
                      ├── account.go                      # package source
                      ├── account_test.go                 # test source
                      ├── ...
                      ├── timestamp.go
                      ├── timestamp_test.go
                      └── util
                          ├── droplet.go
                          └── droplet_test.go
      

      The default directory for the Go workspace as of 1.8 is your user's home directory with a go subdirectory, or $HOME/go. If you are using an earlier version of Go than 1.8, it is still considered best practice to use the $HOME/go location for your workspace

      Issue the following command to navigate to the $HOME directory:

      Next, create the directory structure for your Go workspace:

      This will ensure the following directory structure is now in place:

      └── $HOME
          └── go
              ├── bin
              └── src
      

      Prior to Go 1.8, it was required to set a local environment variable called $GOPATH. While it is no longer explicitly required to do so, it is still considered a good practice as many third party tools still depend on this variable being set.

      Since you used Chocolatey for the installation, this environment variable should already be set. You can verify this with the following command:

      You should see the following output, with your username in place of sammy:

      Output

      C:Userssammygo

      When Go compiles and installs tools, it will put them in the $GOPATH/bin directory. For convenience, it's common to add the workspace's bin subdirectory to your $PATH. You can do this using the setx command in PowerShell:

      • setx PATH "$($env:path);$GOPATHbin"

      This will now allow you to run any programs you compile or download via the Go tools anywhere on your system.

      Now that you have the root of the workspace created and your $GOPATH environment variable set, you will create your future projects with the following directory structure. This example assumes you are using github.com as your repository:

      $GOPATH/src/github.com/username/project
      

      If you were working on the https://github.com/digitalocean/godo project, you would put it in the following directory:

      $GOPATH/src/github.com/digitalocean/godo
      

      Structuring your projects in this manner will make projects available with the go get tool. It will also help readability later.

      You can verify this by using the go get command to fetch the godo library:

      • go get github.com/digitalocean/godo

      Note: If you don't have git installed, Windows will open a dialog box asking if you want to install it. Click Yes to continue and follow the installation instructions.

      You can see it successfully downloaded the godo package by listing the directory:

      • ls $env:GOPATH/src/github.com/digitalocean/godo

      You will receive output similar to this:

      Output

      Directory: C:Userssammygosrcgithub.comdigitaloceangodo Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 4/10/2019 2:59 PM util -a---- 4/10/2019 2:59 PM 9 .gitignore -a---- 4/10/2019 2:59 PM 69 .travis.yml -a---- 4/10/2019 2:59 PM 1592 account.go -a---- 4/10/2019 2:59 PM 1679 account_test.go -rw-r--r-- 1 sammy staff 2892 Apr 5 15:56 CHANGELOG.md -rw-r--r-- 1 sammy staff 1851 Apr 5 15:56 CONTRIBUTING.md . . . -a---- 4/10/2019 2:59 PM 5076 vpcs.go -a---- 4/10/2019 2:59 PM 4309 vpcs_test.go

      In this step, you created a Go workspace and configured the necessary environment variables. In the next step you will test the workspace with some code.

      Step 6 — Creating a Simple Program

      Now that you have the Go workspace set up, create a simple “Hello, World!” program. This will make sure that your workspace is configured properly, and also gives you the opportunity to become more familiar with Go. Because you are creating a single Go source file, and not an actual project, you don't need to be in your workspace to do this.

      From your home directory, open up a command-line text editor, such as nano, and create a new file:

      Once the text file opens up in nano, type out your program:

      hello.go

      package main
      
      import "fmt"
      
      func main() {
          fmt.Println("Hello, World!")
      }
      

      Exit nano by pressing the CTRL and X keys. When prompted to save the file, press Y and then ENTER.

      This code will use the fmt package and call the Println function with Hello, World! as the argument. This will cause the phrase Hello, World! to print out to the terminal when the program is run.

      Once you exit out of nano and return to your shell, run the program:

      The hello.go program that you just created should cause PowerShell to produce the following output:

      Output

      Hello, World!

      In this step, you used a basic program to verify that your Go workspace is properly configured.

      Conclusion

      Congratulations! At this point you have a Go programming workspace set up on your local Windows machine and can begin a coding project!



      Source link